<%@page import="co.gov.medellin.ssti.sub.service.ConsultasService"%>
<%@page
	import="java.util.*,co.gov.medellin.ssti.sub.model.vo.SubprogramaVO,java.util.Vector,co.gov.medellin.ssti.sub.paoyer.administration.model.vo.UserVO,java.text.SimpleDateFormat,java.util.Calendar"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/displaytag.tld" prefix="display"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<link href="<%=request.getContextPath() + "/css/bloques.css"%>"
	rel="stylesheet" type="text/css">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Activar Correcta</title>
</head>
<body>
	<P></P>
	<P></P>

	<%
		Vector codsub = new Vector();
		boolean b = false;
		int modificar;
		Collection<SubprogramaVO> rs = null;		
		ConsultasService consulta = new ConsultasService();
		String strcont = request.getParameter("cont");
		int cont = Integer.parseInt(strcont.trim());
		int i = 0;
		List<SubprogramaVO> noactivar = new LinkedList<SubprogramaVO>();
		List<SubprogramaVO> activos = new LinkedList<SubprogramaVO>();
		for (i = 0; i < cont; i++) {
			String activar = request.getParameter("Activar" + i);
			if (activar != null) {
				b = consulta.valProgActivo(activar);
				if (b) {
					rs = consulta.getInfoact(activar);
					if (rs != null) {
						try {
							Iterator<SubprogramaVO> it = rs.iterator();
							SubprogramaVO objsubprogVO = it.next();
							noactivar.add(objsubprogVO);
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				} else {
					rs = consulta.getInfoact2(activar);
					if (rs != null) {
						try {
							Iterator<SubprogramaVO> it = rs.iterator();							
							SubprogramaVO objsubprogVO = it.next();
							//Proceso para la auditoria
							UserVO user = (UserVO) request.getSession()
									.getAttribute("userInfo");
							String terminalAddress = request
									.getRemoteAddr();
							String strTerminal = ("WEB=" + terminalAddress);
							Calendar c = Calendar.getInstance();
							SimpleDateFormat dateFormat = new SimpleDateFormat(
									"dd/MM/yyyy");
							//Fin del proceso
							String strArr[] = { user.getName(),
									dateFormat.format(c.getTime()),
									strTerminal, activar };
							modificar = consulta.getActivarSub2(strArr);
							activos.add(objsubprogVO);
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				}
			}
		}

		if (noactivar.size() > 1) {
			request.setAttribute("Lista1", noactivar);
		}
		if (noactivar.size() == 1) {
			request.setAttribute("Lista2", noactivar);
		}
		
	%>
	<logic:present scope="request" name="Lista1">
		<div align="center">
			<table cellspacing="2" cellpadding="1" border="0" width="80%"
				align="center">
				<tr>
					<td class="celdatabla" align="center">No es posible activar los beneficios, el programa no est&aacute; activo</td>
				</tr>
			</table>
			<P></P>
			<table cellspacing="3" cellpadding="2" border="0" width="90%"
				align="center">
				<tr>
					<td><display:table name="requestScope.Lista1"
							class="bordesTable" id="list" cellpadding="3" cellspacing="1"
							style="width:100%">
							<display:column headerClass="headerTable" title="Subprograma"
								class="Numero" sortable="false">
								<bean:write name="list" property="nombre" />
							</display:column>
							<display:column headerClass="headerTable" title="Programa"
								class="Numero" sortable="false">
								<bean:write name="list" property="nombrePrograma" />
							</display:column>
							<display:column headerClass="headerTable"
								title="Activar Programa" class="Numero" sortable="false">
								<html:link paramId="Codigo" paramName="list"
									paramProperty="codePrograma"
									page="/subprogramas/ActivarSubprogramas.do?ori=activar1">
									<div align="center">
										<img
											src="<%=request.getContextPath()
									+ "/images/activar.gif"%>"
											width="16" height="16" border="0">
									</div>
								</html:link>
							</display:column>
						</display:table></td>
				</tr>
			</table>
			<P></P>
			<table cellspacing="2" cellpadding="1" border="0" width="80%"
				align="center">
				<tr>
					<td>
						<P>
							<a href="javascript:window.history.back()"> <img
								src="<%=request.getContextPath() + "/images/BACK1-1.gif"%>"
								border="0" />
							</a>
						</P>
					</td>
				</tr>
			</table>
			<P></P>
		</div>
	</logic:present>
	<P></P>
	<logic:present scope="request" name="Lista2">
		<div align="center">
			<table cellspacing="1" cellpadding="2" border="0" width="80%"
				align="center">
				<tr>
					<td class="celdatabla" align="center">No es posible activar el beneficio, el programa no est&aacute; activo</td>
				</tr>
			</table>
			<P></P>
			<div align="center">
				<table class="tablaGenericaWidth90">
					<tr>
						<td><display:table name="requestScope.Lista2"
								class="bordesTable" id="list" cellpadding="3" cellspacing="1"
								style="width:100%">
								<display:column headerClass="headerTable" title="Subprograma"
									class="Numero" sortable="false">
									<bean:write name="list" property="nombre" />
								</display:column>
								<display:column headerClass="headerTable" title="Programa"
									class="Numero" sortable="false">
									<bean:write name="list" property="nombrePrograma" />
								</display:column>
								<display:column headerClass="headerTable"
									title="Activar Programa" class="Numero" sortable="false">
									<html:link paramId="Codigo" paramName="list"
										paramProperty="codePrograma"
										page="/subprogramas/ActivarSubprogramas.do?ori=activar1">
										<div align="center">
											<img
												src="<%=request.getContextPath()
									+ "/images/activar.gif"%>"
												width="16" height="16" border="0">
										</div>
									</html:link>
								</display:column>
							</display:table></td>
					</tr>
				</table>
			</div>
			<P></P>
			<table cellspacing="1" cellpadding="2" border="0" width="80%"
				align="center">
				<tr>
					<td><a href="javascript:window.history.back()"> <img
							src="<%=request.getContextPath() + "/images/BACK1-1.gif"%>"
							border="0" />
					</a></td>
				</tr>
			</table>
		</div>
	</logic:present>
	<%
		if (activos.size() > 0) {
			if (activos.size() > 1) {
				request.setAttribute("Lista3", activos);
			}
			if (activos.size() == 1) {
				request.setAttribute("Lista4", activos);
			}
	%>
	<logic:present scope="request" name="Lista3">
		<div align="center">
			<table cellspacing="2" cellpadding="1" border="0" width="80%"
				align="center">
				<tr>
					<td class="celdatabla" align="center">Los Beneficios fueron
						activados</td>
				</tr>
			</table>
			<P></P>
			<table cellspacing="3" cellpadding="2" border="0" width="90%"
				align="center">
				<tr>
					<td><display:table name="requestScope.Lista3"
							class="bordesTable" id="list" cellpadding="3" cellspacing="1"
							style="width:100%">
							<display:column headerClass="headerTable" title="Beneficio"
								class="Numero" sortable="false">
								<bean:write name="list" property="nombre" />
							</display:column>
							<display:column headerClass="headerTable" title="Programa"
								class="Numero" sortable="false">
								<bean:write name="list" property="nombrePrograma" />
							</display:column>
						</display:table></td>
				</tr>
			</table>
			<P></P>
			<table cellspacing="1" cellpadding="2" border="0" width="80%"
				align="center">
				<tr>
					<td><a
						href="<%=request.getContextPath()
							+ "/programas/ConsultarPrograma.do"%>">Volver
							a Programas</a></td>
					<td><a
						href="<%=request.getContextPath()
							+ "/subprogramas/ConsultarSubprograma.do"%>">Volver
							a Beneficios</a></td>
				</tr>
			</table>
			<P></P>
		</div>
	</logic:present>
	<P></P>
	<logic:present scope="request" name="Lista4">
		<div align="center">
			<table cellspacing="1" cellpadding="2" border="0" width="80%"
				align="center">
				<tr>
					<td class="celdatabla" align="center">El Beneficio fue
						activado</td>
				</tr>
			</table>
			<P></P>
			<table cellspacing="3" cellpadding="2" border="0" width="90%"
				align="center">
				<tr>
					<td><display:table name="requestScope.Lista4"
							class="bordesTable" id="list" cellpadding="3" cellspacing="1"
							style="width:100%">
							<display:column headerClass="headerTable" title="Beneficio"
								class="Numero" sortable="false">
								<bean:write name="list" property="nombre" />
							</display:column>
							<display:column headerClass="headerTable" title="Programa"
								class="Numero" sortable="false">
								<bean:write name="list" property="nombrePrograma" />
							</display:column>
						</display:table></td>
				</tr>
			</table>
			<P></P>
			<table cellspacing="1" cellpadding="2" border="0" width="80%"
				align="center">
				<tr>
					<td><a
						href="<%=request.getContextPath()
							+ "/programas/ConsultarPrograma.do"%>">Volver
							a Programas</a></td>
					<td><a
						href="<%=request.getContextPath()
							+ "/subprogramas/ConsultarSubprograma.do"%>">Volver
							a Beneficios</a></td>
				</tr>
			</table>
		</div>
	</logic:present>
	<%
		}
	%>
</body>
</html>
